/*
 * Copyright (c) 2025 Li Auto Inc. and its affiliates
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef SRC_CPP_RTPS_TRANSPORT_IPCSENDERRESOURCE_HPP_
#define SRC_CPP_RTPS_TRANSPORT_IPCSENDERRESOURCE_HPP_

#include <ertps/utils/LocatorAlias.h>
#include <transport/SenderResource.h>

#include "IPCTransport.h"

namespace vbs {
namespace transport {

class IPCSenderResource : public vbs::transport::SenderResource {
 public:
    IPCSenderResource(IPCTransport& transport, uint32_t order = 65535)
        : SenderResource(transport.kind()), transport_(transport) {
        // Implementation functions are bound to the right transport parameters

        send_lambda_ = [this, &transport](unsigned char* data, uint32_t dataSize,
                                          vbsutil::xmlparser::LocatorsIterator* destination_locators_begin,
                                          vbsutil::xmlparser::LocatorsIterator* destination_locators_end) -> bool {
            return transport.send(data, dataSize, destination_locators_begin, destination_locators_end);
        };
        order_ = order;
    }

    ~IPCSenderResource() {}

 private:
    IPCSenderResource() = delete;

    IPCSenderResource(const SenderResource&) = delete;

    IPCSenderResource& operator=(const SenderResource&) = delete;

    IPCTransport& transport_;
};

}  // namespace transport
}  // namespace vbs

#endif  // SRC_CPP_RTPS_TRANSPORT_IPCSENDERRESOURCE_HPP_
